<?php
namespace app\admin\model;
use think\Model;
use think\Db;

/**
 * 回调订单导出模型
 * @package app\admin\model
 */
class OrderCallbackExportM extends Model
{
	protected $table = 'bus_order';

	public function getOrderAll($request, $all = 0)
	{
		$data = $this::alias('b')->field('b.cid, b.trade_id, b.channel_order_id, b.plat_id, b.sms_size, p.phone, p.order_phone_code, p.order_phone_msg, p.price, p.create_time, p.phone_callback_time, c.bus_push_sms')
				->join('bus_order_phone_50 p', 'b.id = p.order_table_id', 'left')
				->join('bus_order_sms_content c', 'b.id = c.bus_order_id', 'left');
				
		$data = $data->where('b.create_time', 'between time', [$request['st'], $request['et']]);

		if($request['cid']) {

			$data = $data->where('b.cid', $request['cid']);
		}

		if ($all == 1) {

			return $data->order('b.create_time desc')->select();

		} else {

			return $data->order('b.create_time desc')->paginate($request['limit'], false, $request);
		}
		
	}

	public function getOrderExport($request, $page = 1, $limit = 20000)
	{
		$data = $this::alias('b')->field('b.cid, b.trade_id, b.channel_order_id, b.plat_id, b.sms_size, p.phone, p.order_phone_code, p.order_phone_msg, p.price, p.create_time, p.phone_callback_time, c.bus_push_sms')
				->join('bus_order_phone_50 p', 'b.id = p.order_table_id', 'left')
				->join('bus_order_sms_content c', 'b.id = c.bus_order_id', 'left');
				
		$data = $data->where('b.create_time', 'between time', [$request['st'], $request['et']]);

		if($request['cid']) {

			$data = $data->where('b.cid', $request['cid']);
		}

		return $data->order('b.create_time desc')->page($page . ',' . $limit)->select();
	}

	public function getCount($request)
	{
		$data = $this::alias('b')->field('b.cid, b.trade_id, b.channel_order_id, b.plat_id, b.sms_size, p.phone, p.order_phone_code, p.order_phone_msg, p.price, p.create_time, p.phone_callback_time, c.bus_push_sms')
				->join('bus_order_phone_50 p', 'b.id = p.order_table_id', 'left')
				->join('bus_order_sms_content c', 'b.id = c.bus_order_id', 'left');
				
		$data = $data->where('b.create_time', 'between time', [$request['st'], $request['et']]);

		if($request['cid']) {

			$data = $data->where('b.cid', $request['cid']);
		}

		return $data->count();
	}



}